<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>axios查询所有用户并表格展示</title>
    <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
    <script type="module">
        //引入vue3
        import {createApp} from 'https://unpkg.com/vue@3/dist/vue.esm-browser.js'
        const app = createApp({
            data() {
                return {
                    users: [] // 修改变量名为 users，与模板中的绑定一致
                }
            },
            mounted() {
                axios.get('http://localhost:8099/user/all').then((result) => {
                    console.log(result.data.data);
                    this.users = result.data.data; // 将请求结果赋值给 users
                }).catch((err) => {
                    console.log(err);
                })
            }
        }).mount('#app')
    </script>
    <style>
        /* 添加表格样式 */
        table {
            width: 100%;
            border-collapse: collapse;
            margin-top: 20px;
        }
        th, td {
            padding: 10px;
            text-align: center;
            border: 1px solid #ccc;
        }
        th {
            background-color: #f2f2f2;
        }
    </style>
</head>
<body>
<div>
    <div id="app">
        <table border="1">
            <td>
                <a href="#">修改</a>
                <a href="#">删除</a>
            </td>
            <tr>
                <th>编号</th>
                <th>用户名</th>
                <th>详情信息</th>
                <th>状态</th>
                <th>余额</th>
                <th>操作</th>
            </tr>
            <!-- 删除: <tr v-for="user in users"> -->
            <tr v-for="user in users" :key="user.id"> <!-- 添加 key 属性 -->
                <td>{{ user.id }}</td>
                <td>{{ user.username }}</td>
                <td>{{ user.info }}</td>
                <td>{{ user.status }}</td>
                <td>{{ user.balance }}</td>
                <td>
                    <a href="">修改</a>
                    <a href="">删除</a>
                </td>
            </tr>
        </table>
    </div>
</div>
</body>
</html>

